package vip.xiaonuo.smzq.modular.kcl.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.kcl.entity.Ckqsqdj;
import vip.xiaonuo.smzq.modular.kcl.mapper.CkqsqdjMapper;
import vip.xiaonuo.smzq.modular.kcl.service.ICkqsqdjService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;

/**
 * 采矿权申请登记基本信息 服务实现类
 *
 * @author sqq
 * @since 2024-03-19
 */
@Service
public class CkqsqdjServiceImpl extends ServiceImpl<CkqsqdjMapper, Ckqsqdj> implements ICkqsqdjService {

    @Resource
    private CkqsqdjMapper ckqsqdjMapper;

    @Override
    public Page<Ckqsqdj> page(Ckqsqdj ckqsqdj) {
        QueryWrapper<Ckqsqdj> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Override
    public Ckqsqdj getCkqsqdj(Integer nd, String kqbm, Integer djflbm) {
        QueryWrapper<Ckqsqdj> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("nd", nd).eq("kqbh", kqbm).eq("djflbh", djflbm);
        return ckqsqdjMapper.selectOne(queryWrapper);
    }

    /**
     * 更新采矿权申请登记基本信息
     * @param ckqsqdj
     * @param kqbh
     * @param djflbm
     * @param nd
     * @return
     */
    @Override
    public int addCkqsqdj(Ckqsqdj ckqsqdj, String kqbh, Integer djflbm, Integer nd) {
        int count = 0;
        ckqsqdj.setKqbh(kqbh);
        ckqsqdj.setDjflbh(djflbm);
        ckqsqdj.setNd(nd);
        if (ckqsqdj.getPkid()!= null&& ckqsqdj.getPkid().length()>0){

            count =ckqsqdjMapper.updateById(ckqsqdj);
        }else{
            count = ckqsqdjMapper.insert(ckqsqdj);
        }
        return count;
    }
}
